package com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyAdapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.diudiutechnology.www.yadiudiu.util.http.User;
import com.diudiutechnology.www.yadiudiu.util.utils.RatingBar;
import com.diudiutechnology.www.yadiudiu.yadiudiu.model.BuyACarFragmentModel;
import com.diudiutechnology.www.yadiudiu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/14.
 * 购车
 */

public class BuyACarFragmentAdapter extends BaseAdapter {

    private Context mContext;
    private  int countday=0;
    ArrayList<User.DataBean.StrokeList> toolList;
//    List<BuyACarFragmentModel> model= new ArrayList<>();
    public BuyACarFragmentAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return toolList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
//    public void addItem( List<BuyACarFragmentModel> model,int countday){
//        this.countday=countday;
//        this.model=model;
//        notifyDataSetChanged();
//    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_buyacar, null);
            holder.item_image = (ImageView) convertView
                    .findViewById(R.id.item_image);
            holder.item_title = (TextView) convertView
                    .findViewById(R.id.item_title);
            holder.rating = (RatingBar) convertView
                    .findViewById(R.id.rating);
            holder.item_time = (TextView) convertView
                    .findViewById(R.id.item_time);
            holder.item_site = (TextView) convertView
                    .findViewById(R.id.item_site);
            holder.item_sites = (TextView) convertView
                    .findViewById(R.id.item_sites);
            holder.item_money = (TextView) convertView
                    .findViewById(R.id.item_money);
            holder.item_moneys = (TextView) convertView
                    .findViewById(R.id.item_moneys);
            holder.positioning_text = (TextView) convertView
                    .findViewById(R.id.positioning_text);
            holder.browse_text = (TextView) convertView
                    .findViewById(R.id.browse_text);
            holder.comments_text = (TextView) convertView
                    .findViewById(R.id.comments_text);
            holder.browse = (ImageView) convertView
                    .findViewById(R.id.browse);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
//        if (countday==0){
//            if (position==0){
//                holder.item_image.setImageResource(R.mipmap.imcar_cheshi1);
//            }else {
//                holder.item_image.setImageResource(R.mipmap.imcar_cheshi2);
//            }
//
//            holder.item_site.setText(mContext.getResources().getString(R.string.theguided));
//            holder.item_money.setText(mContext.getResources().getString(R.string.thesaleprice));
//            holder.browse.setImageResource(R.mipmap.browse);
//        }else {
//            if (position==0){
//                holder.item_image.setImageResource(R.mipmap.imwash_the_car1);
//            }else if (position==1){
//                holder.item_image.setImageResource(R.mipmap.imwash_the_car2);
//            }else {
//                holder.item_image.setImageResource(R.mipmap.imwash_the_car3);
//            }
//            holder.item_site.setText(mContext.getResources().getString(R.string.storeprice));
//            holder.item_money.setText(mContext.getResources().getString(R.string.diudiuprice));
//            holder.browse.setImageResource(R.mipmap.theorder);
//        }

//        BuyACarFragmentModel bModel = model.get(position);
        holder.item_title.setText(toolList.get(position).name);
        holder.item_time.setText(toolList.get(position).brand);


        holder.item_sites.setText(toolList.get(position).guideprice+"元");
        holder.item_sites.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG|Paint.ANTI_ALIAS_FLAG);

      //
        holder.item_moneys.setText(toolList.get(position).sellingprice+"元");
        holder.positioning_text.setText(toolList.get(position).km+"km");
        holder.browse_text.setText(toolList.get(position).thenumberof);
        holder.comments_text.setText(toolList.get(position).countcomment);

        holder.rating.setClickable(false);//设置可否点击
        holder.rating.setStar(toolList.get(position).star);//设置显示的星星个数

        Glide.with(mContext.getApplicationContext()).load("图片拼接串").asBitmap() .
                error(R.mipmap.imwash_the_car2).
                centerCrop().diskCacheStrategy(DiskCacheStrategy.RESULT ) .into(holder.item_image);
        return convertView;
    }

    class ViewHolder {
        ImageView item_image;
        TextView item_title;
        RatingBar rating;
        TextView item_time;
        TextView item_site;
        TextView item_sites;
        TextView item_money;
        TextView item_moneys;
       TextView positioning_text;
        TextView browse_text;
        TextView comments_text;
        ImageView browse;
    }
}

